package com.woniuxy.yoga.product.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.yoga.commons.core.model.PageInfo;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import com.woniuxy.yoga.product.dao.model.PrivateProduct;
import com.woniuxy.yoga.product.model.dto.PrivateProductByIdDTO;
import com.woniuxy.yoga.product.model.form.AddPrivateProductForm;
import com.woniuxy.yoga.product.model.form.QueryNormalPrivateProductForm;
import com.woniuxy.yoga.product.model.form.QueryPrivateProductForm;
import com.woniuxy.yoga.product.model.param.AddPrivateProductParam;
import com.woniuxy.yoga.product.model.param.QueryNormalPrivateProductParam;
import com.woniuxy.yoga.product.model.param.QueryPrivateProductParam;
import com.woniuxy.yoga.product.service.service.PrivateProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 私人产品表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年12月06日
 */
@RestController
@RequestMapping("/privateProduct")
@Api(tags = "私教产品服务相关业务接口")
@Validated
public class PrivateProductController {

    @Autowired
    private PrivateProductService privateProductService;

    /**
     * 私教产品ID查询私教产品
     * @param privateProductId
     * @return
     */
    @GetMapping("/getById/{privateProductId}")
    @ApiOperation("私教产品ID查询私教产品接口")
    @ApiImplicitParam(name = "privateProductId",value = "私教产品ID")
    public Result<PrivateProductByIdDTO> getById(@Valid @NotNull(message = "私教产品ID不能为空") @PathVariable("privateProductId") Integer privateProductId){
        //获取数据
        PrivateProduct privateProduct = privateProductService.getById(privateProductId);
        //对象转换
        PrivateProductByIdDTO privateProductByIdDTO = BeanUtil.toBean(privateProduct, PrivateProductByIdDTO.class);
        //返回数据
        return Result.getResult(PrivateProductByIdDTO.class).setMessage("根据私教产品ID查询私教产品成功").setData(privateProductByIdDTO);
    }

    /**
     * 新增私教产品
     * @param addPrivateProductForm
     * @return
     */
    @PostMapping("/addPrivateProduct.bu")
    @ApiOperation("新增私教产品接口")
    public Result<?> addPrivateProduct(@Valid @RequestBody AddPrivateProductForm addPrivateProductForm) throws Exception{
        privateProductService.addPrivateProduct(BeanUtil.toBean(addPrivateProductForm, AddPrivateProductParam.class));
        return Result.getResult().setMessage("新增私教产品成功");
    }

    /**
     * 私教产品上架
     * @param privateProductId
     * @return
     */
    @GetMapping("/normalPrivateProduct/{privateProductId}.bu")
    @ApiOperation("私教产品上架接口")
    @ApiImplicitParam(name = "privateProductId",value = "私教产品ID")
    @YogaLog("私教产品上架")
    public Result<?> normalPrivateProduct(@Valid @NotNull(message = "私教产品ID不能为空") @PathVariable("privateProductId") Integer privateProductId){
        privateProductService.normalPrivateProduct(privateProductId);
        return Result.getResult().setMessage("私教产品上架成功");
    }

    /**
     * 私教产品下架
     * @param privateProductId
     * @return
     */
    @GetMapping("/disablePrivateProduct/{privateProductId}.bu")
    @ApiOperation("私教产品下架接口")
    @ApiImplicitParam(name = "privateProductId",value = "私教产品ID")
    @YogaLog("私教产品下架")
    public Result<?> disablePrivateProduct(@Valid @NotNull(message = "私教产品ID不能为空") @PathVariable("privateProductId") Integer privateProductId){
        privateProductService.disablePrivateProduct(privateProductId);
        return Result.getResult().setMessage("私教产品下架成功");
    }

    /**
     * 私教产品删除
     * @param privateProductId
     * @return
     */
    @GetMapping("/deletePrivateProduct/{privateProductId}.bu")
    @ApiOperation("私教产品删除接口")
    @ApiImplicitParam(name = "privateProductId",value = "私教产品ID")
    @YogaLog("私教产品删除")
    public Result<?> deletePrivateProduct(@Valid @NotNull(message = "私教产品ID不能为空") @PathVariable("privateProductId") Integer privateProductId){
        privateProductService.deletePrivateProduct(privateProductId);
        return Result.getResult().setMessage("私教产品删除成功");
    }

    /**
     * 判断该教练是否存在私教产品
     * @param coachId
     * @return
     */
    @GetMapping("/checkExistByCoachId/{coachId}")
    @ApiOperation("判断该教练是否存在私教产品接口")
    @ApiImplicitParam(name = "coachId",value = "教练ID")
    public Result<PrivateProductByIdDTO> checkExistByCoachId(@Valid @NotNull(message = "教练ID不能为空") @PathVariable("coachId") Integer coachId){
        PrivateProductByIdDTO privateProductByIdDTO = privateProductService.checkExistByCoachId(coachId);
        return Result.getResult(PrivateProductByIdDTO.class).setMessage("判断该教练是否存在私教产品成功").setData(privateProductByIdDTO);
    }

    /**
     * 商家查询所有私教产品信息
     * @param queryPrivateProductForm
     * @return
     */
    @PostMapping("/queryPrivateProduct.bu")
    @ApiOperation("商家查询所有私教产品信息接口")
    public Result<PageInfo> queryPrivateProduct(@Valid @RequestBody QueryPrivateProductForm queryPrivateProductForm){
        PageInfo pageInfo = privateProductService.queryPrivateProduct(BeanUtil.toBean(queryPrivateProductForm, QueryPrivateProductParam.class));
        return Result.getResult(PageInfo.class).setMessage("商家查询所有私教产品信息成功").setData(pageInfo);
    }

    /**
     * 批量删除私教产品
     * @param storeId
     * @return
     */
    @GetMapping("/removePrivateProduct/{storeId}")
    @ApiOperation("批量删除私教产品接口")
    @ApiImplicitParam(name = "storeId",value = "门店ID")
    public Result<?> removePrivateProduct(@Valid @NotNull(message = "门店ID不能为空") @PathVariable("storeId") Integer storeId){
        privateProductService.removePrivateProduct(storeId);
        return Result.getResult().setMessage("批量删除私教产品成功");
    }

    /**
     * 用户查询正常私教产品
     * @param storeId
     * @return
     */
    @PostMapping("/userQueryNormalPrivateProduct.us")
    @ApiOperation("用户查询正常私教产品接口")
    public Result<PageInfo> queryNormalPrivateProduct(@RequestBody QueryNormalPrivateProductForm queryNormalPrivateProductForm){
        PageInfo pageInfo = privateProductService.userQueryNormalPrivateProduct(BeanUtil.toBean(queryNormalPrivateProductForm, QueryNormalPrivateProductParam.class));
        return Result.getResult(PageInfo.class).setMessage("用户查询正常私教产品成功").setData(pageInfo);
    }
}

